package cn.edu.hqu.cst.android.ex3demo;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class MainActivity<OuterClassListener> extends AppCompatActivity implements View.OnClickListener {
    TextView show_action;
    Button activity,inner,anonymous,lambda,outer,show_system_info,show_progress_dialog;
    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        show_action=findViewById(R.id.show_action);

        activity=findViewById(R.id.activity);
        inner=findViewById(R.id.inner);
        anonymous=findViewById(R.id.anonymous);
        lambda=findViewById(R.id.lambda);
        outer=findViewById(R.id.outer);
        show_system_info=findViewById(R.id.show_system_info);
        show_progress_dialog=findViewById(R.id.show_progress_dialog);

        activity.setOnClickListener(this);
        inner.setOnClickListener(new InnerClassListener());

        //匿名内部类作为监听器
        anonymous.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                show_action.setText("匿名内部类作为监听器");
            }
        });
        lambda.setOnClickListener(View->show_action.setText("lambda表达式作为监听器"));
        outer.setOnClickListener(new cn.edu.hqu.cst.android.ex3demo.OuterClassListener(show_action));

        show_system_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("MainActivity","cfqp");
                Intent intent=new Intent(MainActivity.this,SystemInfoActivity.class);
                startActivity(intent);
            }
        });

        show_progress_dialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,progressDialogTest.class);
                startActivity(intent);
            }
        });


    }//onCreate()

    @SuppressLint("SetTextI18n")
    @Override
    public void onClick(View v) {
        show_action.setText("Activity作为监听器");
    }



    private  class InnerClassListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            show_action.setText("内部类作为监听器");
        }
    }
    public  void clickHandler(View v){
        show_action.setText("监听器绑定到标签");
    }


}

class OuterClassListener implements View.OnClickListener {
    TextView show_action;

    public OuterClassListener(TextView show_action) {
        this.show_action = show_action;
    }

    @Override
    public void onClick(View v) {
        show_action.setText("外部类作为监听器");
    }
}